package com.aikg.kgrag_java.config;

import org.neo4j.driver.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @ClassName: Neo4jConfig
 * @Description: neo4j配置类
 * @Author: 李宗雨
 * @Date: 2025/1/4 11:18
 * @Version: 1.0
 **/
@Configuration
@EnableTransactionManagement
public class Neo4jConfig {

    @Value("${spring.neo4j.uri}")
    private String uri;

    @Value("${spring.neo4j.authentication.username}")
    private String username;

    @Value("${spring.neo4j.authentication.password}")
    private String password;

    @Bean(name = "neo4jDriver")
    public Driver neo4jDriver() {
        Config config = Config.builder().build();
        return GraphDatabase.driver(uri, AuthTokens.basic(username, password));
    }

    @Bean(name = "neo4jSession")
    public Session neo4jSession(@Qualifier("neo4jDriver") Driver driver) {
        return driver.session();
    }

}